/****
 * created By 北大课工场 kgc
 * @param a
 * @param b
 * @param c
 * @param d
 */
var goodsId=1;
var getGoodsStatusTimer;
//加载百分比
function loadPercent(width,total,discountPrice,price){
    $('.ec_jinDu').width(width);
    $('.bfb').html(width);
    $('.sz').html(total);
    $('.x_jiaGe').html(discountPrice);
    $('.d_jiaGe').html(price);
}
//初始化加载
$(function () {
   loadGoodInfo();
});
function qgGoods() {
    var token=getCookie("token");
    $.ajax({
        url : ReqUrl.GoodsReqUrl()+"/sendQgGoodsMessage",
        type : "post",
        dataType : "json",
        data : {
            goodsId : goodsId,
            token : token
        },
        success: function(response, status, xhr){
            // alert(response.message);
            if(response.code === 0){
                dialog.show({
                    'message':"抢购消息发送成功,正在排队中...",
                    'isCountDown':false,
                });
                getGoodsStatusTimer = setInterval(function(){
                    getGetGoodsStatus(goodsId);
                },1500);
            }

        }
    });
};

/**
 * 获取抢购商品的状态
 * @param goodsId
 */
function getGetGoodsStatus(goodsId){
    $.ajax({
        url: ReqUrl.GoodsReqUrl() + "getGoodsStatus",
        type: "post",
        dataType: "json",
        data: {
            goodsId: goodsId,
            token: getCookie("token")
        },
        success:function (response) {
            console.log(response);
            // 1 表示成功 0 表示已经卖完 2表示之前已经成功抢购过的, -1 正在排队中
            if( response.data === "1" ){
                window.clearInterval(getGoodsStatusTimer);
                dialog.close();
                dialog.show({
                    'message':"抢购成功!",
                    'isCountDown':true,
                    'seconds':2,
                    callback: function(){
                        window.location.href="orderList.html";
                    }
                });
            }else if(response.data === "0"){
                window.clearInterval(getGoodsStatusTimer);
                dialog.close();
                dialog.show({
                    'message':"抢购失败,已经被抢完了!",
                    'isCountDown':true,
                    'seconds':2,
                    callback: function(){
                        window.location.reload();
                    }
                });
            }else if(response.data === "2"){
                window.clearInterval(getGoodsStatusTimer);
                dialog.close();
                dialog.show({
                    'message':"已经参加过抢购,不能再次抢购!",
                    'isCountDown':true,
                    'seconds':2,
                    callback: function(){
                        window.location.reload();
                    }
                });
            }
        }
    });
}

window.alert=function (message) {
    dialog.show({
        'message':message,
        'isCountDown':true,
        'seconds':3,
        callback: function(){
            console.info("查询抢购结果...");
        }
    });
};
// dialog.show({
//     'logoType':1,
//     'message':'抢购成功',
//     'isCountDown':false,
// });



/*$(function() {
    $(".top-anNiu1").click(function() {
        $(".btn-show").show().siblings("div").hide()
    });
    $(".btn-show").click(function() {
        $(".bian_kuang-biaoDan").show()
    });
    $(".btn-qieHuan").click(function() {
        $(".bian_kuang-biaoDan").toggle().siblings("div").show();
    });


    $(".top-anNiu2").click(function() {
        $(".bian_kuang-biaoDan").hide().siblings("div").hide()
    })
});*/